<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}

		if(isset($_SESSION['lang']))
		$lang=$_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../operations/connection.php';
$ktview=1;
$tinh_trang_bang_luong="";
$nguoitao="";
$ngaytao="";
$nguoicn="";
$ngaycn="";
$mem=array();
if(isset($_REQUEST[nam]) && isset($_REQUEST[thang])){
	$thang=$_REQUEST[thang];
	$nam=$_REQUEST[nam];
	$idlog=$_REQUEST[nam]."-".$_REQUEST[thang];
	$ktquery="SELECT sa_employee_salary_log.idlog,
	sa_employee_salary_log.date_create,
	sa_employee_salary_log.date_last_update,
	sa_employee_salary_log.is_saved,uc.FullName as uscreate, lu.FullName as uslastupdate  
	from sa_employee_salary_log left JOIN employee uc on sa_employee_salary_log.user_create=uc.IDEmployee 
	left join employee lu on sa_employee_salary_log.user_last_update=lu.IDEmployee 
	where sa_employee_salary_log.idlog='".$idlog."'";
	$mktquery=mysql_query($ktquery);
	if(mysql_num_rows($mktquery)>0){
		$ktview=0;
		while($r=mysql_fetch_array($mktquery)){
			if($r[is_saved]==0){
				$tinh_trang_bang_luong=$l_temporary_storage;
			}else{
				$tinh_trang_bang_luong=$l_confirm_and_save;
			}
			$nguoitao=$r[uscreate];
			$ngaytao=$r[date_create];
			$nguoicn=$r[uslastupdate];
			$ngaycn=$r[date_last_update];
		}
	}
		
	if($ktview==0){
		$query="SELECT sa_employee_salary.*, employee.FullName, employee.Position,employee.IDEmployee,employee.Type_employee   
		from sa_employee_salary, employee 
		where employee.IDEmployee=sa_employee_salary.employeeID ";
		if($thang !="" && $nam!=""){
			$query .=" and sa_employee_salary.sa_time='".$idlog."'";
		}
		/*if($nhanvien!="ALL"){
			$query .=" and  employee.IDEmployee='".$nhanvien."'";
		}*/
		$query .=" and employee.State=1 order by  employee.IDEmployee asc";
		
		$result=mysql_query($query);
		if(mysql_num_rows($result)>0){
			while($row=mysql_fetch_array($result)){
				$t=array();
				$t[employeeID]=$row[IDEmployee];
				$t[name]=$row[FullName];
				$t[position]=$row[Position];
				$t[number_time_work]=$row[number_time_work];
				$t[really_number_time_work]=$row[really_number_time_work];
				$t[number_allow_holiday]=$row[number_allow_holiday];
				$t[basic_salary]=$row[basic_salary];
				$t[allowance_basic_salary]=$row[allowance_basic_salary];
				
				$t[number_dateoff]=$row[number_dateoff];
				$t[number_holiday]=$row[number_holiday];
				
				$t[number_is_comeback_early]=$row[number_is_comeback_early];
				
				$t[number_is_late]=$row[number_is_late];
				$t[allowance_senior]=$row[allowance_senior];
				$t[allowance_c]=$row[allowance_c];
				
				$t[oneday_salary]=$row[oneday_salary];
				
				$t[paid_salary]=$row[paid_salary];
				
				$t[allowance_holiday]=$row[allowance_holiday];
				$t[allowance_lunch]=$row[allowance_lunch];
				$t[allowance_car]=$row[allowance_car];
				
				$t[allowance_hard]=$row[allowance_hard];
				
				
				$t[number_overtime]=$row[number_overtime];
				$t[overtime_salary]=$row[overtime_salary];
				
				$t[total_salary]=$row[total_salary];
				
				$t[insurance]=$row[insurance];
				$t[salary_bornus]=$row[salary_bornus];
				$t[salary_sub]=$row[salary_sub];
				
				$t[received_salary]=$row[received_salary];
				
				$t[note]=$row[note];
				$t[is_saved]=$row[is_saved];
				$t[is_sendmail]=$row[is_sendmail];
				$t[Type_employee]=$row[Type_employee];
				
				$mem[$row[IDEmployee]]=$t;
			}
			//print_r($mem);
		}	
	}
}
?>
<table style="width:820px;">
					<tr>
						<td><b><?php echo $l_salary_satus;?></b></td>
					</tr>
					<tr>
						<td>
							<table style="padding:10px 5px" width="100%; background:white;">
								<tr>
									<td class="tdfirst"><?php echo $l_time;?></td>
									<td colspan="3" class="in_testfield" style="background:white;" ><?php echo $thang."-".$nam;?></td>
								</tr>
								<tr>
									<td class="tdfirst"><?php echo $l_salary_satus;?></td>
									<td colspan="3" class="in_testfield" style="background:white;"  ><?=$tinh_trang_bang_luong?></td>
								</tr>
								<tr>
									<td class="tdfirst"><?php echo $l_create_by;?></td>
									<td class="in_testfield"  style="background:white;" ><?=$nguoitao?></td>
									<td class="tdfirst"><?php echo $l_first_create;?></td>
									<td class="in_testfield" style="background:white;"  ><?=$ngaytao?></td>
								</tr>
								<!--<tr>
									<td class="tdfirst"><?php echo $l_user_last_update;?></td>
									<td class="in_testfield"  style="background:white;" ><?=$nguoicn?></td>
									<td class="tdfirst"><?php echo $l_time_last_update;?></td>
									<td class="in_testfield" style="background:white;"  ><?=$ngaycn?></td>
								</tr>  -->
							</table>
						</td>
					</tr>
				</table>
			
			<div style=" max-width: 100%" id="showsalary">
				<table class="rf-dt" width="100%">
					<tr>
						<!-- <th rowspan="2" class="rf-dt-shdr-c"></th> -->
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_no;?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_employee_name?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_position?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_number_time_work?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_num_allow_holiday?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_basicsalary?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_allowancebasicsalary?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_dayoff?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_absentmonth?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_comebackearly?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo  $l_comelately?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_allowanceSenior?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_allowanceC?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_salaryperday?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_salaryreceived?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_allowance_holiday?></th>
						<th colspan="2" class="rf-dt-shdr-c"><?php echo $l_allowance?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_allowance_hard?></th>
						<th colspan="2" class="rf-dt-shdr-c"><?php echo $l_allowance_overtime?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_total?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_socialInsurance?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_salary_bonus?></th>
						<!-- <th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_salary_sub?></th> -->
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_realreceived?></th>
						<th rowspan="2" class="rf-dt-shdr-c"><?php echo $l_note;?></th>
					</tr>
					<tr>
						<th class="rf-dt-shdr-c"><?php echo $l_lunch?></th>
						<th class="rf-dt-shdr-c"><?php echo $l_parking?></th>
						<th class="rf-dt-shdr-c"><?php echo $l_numbersession?></th>
						<th class="rf-dt-shdr-c"><?php echo $l_total_amount?></th>
					</tr>
					<tr style="background: #93cddd; color: white">
						<!--  <td class="rf-dt-c"></td> -->
						<td class="rf-dt-c"></td>
						<td class="rf-dt-c">(2)</td>
						<td class="rf-dt-c">(3)</td>
						<td class="rf-dt-c">(4)</td>
						<td class="rf-dt-c"></td>
						<td class="rf-dt-c">(5)</td>
						<td class="rf-dt-c">(6)</td>
						<td class="rf-dt-c">(7)</td>
						<td class="rf-dt-c">(8)</td>
						<td class="rf-dt-c">(9)</td>
						<td class="rf-dt-c">(10)</td>
						<td class="rf-dt-c">(11)</td>
						<td class="rf-dt-c">(12)</td>
						<td class="rf-dt-c">(13)=[(5)+(6) +(11)+(12)]/4</td>
						<td class="rf-dt-c">(14)=(13) x [(4)-7)]</td>
						<td class="rf-dt-c">(15)</td>
						<td class="rf-dt-c">(16)</td>
						<td class="rf-dt-c">(17)</td>
						<td class="rf-dt-c">(18)</td>
						<td class="rf-dt-c">(19)</td>
						<td class="rf-dt-c">(20)= 240000x(19)</td>
						<td class="rf-dt-c">(21)=(14)+(15) +(16)+(17) +(28)+(20)</td>
						<td class="rf-dt-c">(22)</td>
						<td class="rf-dt-c">(23)</td>
						<!-- <td class="rf-dt-c">(24)</td> -->
						<td class="rf-dt-c">(24)=(21)+(23)-(22)</td>
						<td class="rf-dt-c"></td>
					</tr>
					
					<?php 
						$sum_received=0;
						if(count($mem)>0){
							$vitri=0;
							foreach($mem as $khoa=>$giatri){
								?>
								<tr class="hang">
								
									<!-- <td class="rf-dt-c"><input type="checkbox" name="list" id="<?php echo "check".$khoa;?>" value="<?=$khoa?>"/></td> -->
									<td class="rf-dt-c"><?php echo ($vitri+1);?></td>
									<td class="rf-dt-c"><?php echo $giatri[name];?></td>
									<td class="rf-dt-c"><?php echo $giatri[position];?></td>
									<td class="rf-dt-c"><?php echo $giatri[really_number_time_work]."/".$giatri[number_time_work];?></td>
									<td class="rf-dt-c"><?php echo $giatri[number_allow_holiday];?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[basic_salary]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[allowance_basic_salary]);?></td>
									<td class="rf-dt-c"><?php echo $giatri[number_dateoff];?></td>
									<td class="rf-dt-c"><?php echo $giatri[number_holiday];?></td>
									<td class="rf-dt-c"><?php echo $giatri[number_is_comeback_early];?></td>
									<td class="rf-dt-c"><?php echo $giatri[number_is_late];?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[allowance_senior]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[allowance_c]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[oneday_salary]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[paid_salary]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[allowance_holiday]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[allowance_lunch]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[allowance_car]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[allowance_hard]);?></td>
									<td class="rf-dt-c"><?php echo $giatri[number_overtime];?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[overtime_salary]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[total_salary]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[insurance]);?></td>
									<td class="rf-dt-c"><?php echo number_format($giatri[salary_bornus]);?></td>
									<!-- <td class="rf-dt-c"><?php echo number_format($giatri[salary_sub]);?></td> -->
									<td class="rf-dt-c"><?php echo number_format($giatri[received_salary]);?></td>
									<td class="rf-dt-c"><?php echo $giatri[note];?></td>
								</tr>
								<?php 
								$vitri++;
								$sum_received +=$giatri[received_salary];
							}
						}else{
							?>
							<tr><td colspan="26"><?php echo $l_list_emplty;?></td></tr>
							<?php 
						}
					?>
					<tr>
						<td colspan="24" class="rf-dt-c"></td>
						<td class="rf-dt-c" style="background: #93cddd;font-weight: bold;"><?php echo number_format($sum_received);?></td>
						<td class="rf-dt-c"></td>
					</tr>
				</table> 
			</div>
			<div style="width:100%;align:center;" id="showtb">
				<input type="hidden" name="viewthongbao" id="viewthongbao" value="<?php echo $_SESSION['thongbao_employee_salary'];?>" />
				<?php 
				if(count($mem)>0 && $ktview==0){
					?>
					<table width="100%">
						<tr>
							<td align="center">
								<a href="content_salary/ajax_export_salary.php?year=<?=$_REQUEST['nam']?>&month=<?=$_REQUEST['thang']?>"><input type="button" name="btexcel" id="btexcel" value="<?php echo $l_export_excel?>"  class="btnupbg btnupload" /></a>
							</td>
						</tr>
					</table>
					<?php 
				}
				?>
			</div>
			<div style="margin-top: 15px; text-align: center; padding-right: 10px">
			<?php 
				if(count($mem)>0 && $ktview==1){
					?>
					<table width="100%">
						<tr>
							<td width="30px"><img src="images/bonus-icon.gif" width="30px" height="30px" ></td>
							<td class="tdfirst" style="text-align: left;"><?php echo $l_num_allow_holiday;?></td>
							<td style="text-align:left;"  >
								<input onkeypress="return enterTable(event,this.id,'1');" style="width:200px;height:24px" type="text" id="txtholiday" name="txtholiday" value="<?=$_REQUEST['txtbonus']?>" />
								<?php echo $l_note;?>
								<input onkeypress="return enterTable(event,this.id,'0');" style="width:200px;height:24px" type="text" id="txtnoteholiday" name="txtnoteholiday" value="<?=$_REQUEST['txtnote']?>" />
								<input type="button" name="btholidayok" onclick="holiday(1);" id="btholidayok" value="<?php echo $l_ok?>"  class="buttonProject" />
								<input type="button" name="btholidaycancel" onclick="holiday(0);" id="btholidaycancel" value="<?php echo $l_cancel?>"  class="buttonProject" />
							</td>
						</tr>
						<tr>
							<td width="30px"><img src="images/bonus-icon.gif" width="30px" height="30px" ></td>
							<td class="tdfirst" style="text-align: left;"><?php echo $l_bonus_holidays;?></td>
							<td style="text-align:left;"  >
								<input onkeypress="return enterTable(event,this.id,'1');" style="width:200px;height:24px" type="text" id="txtbonus" name="txtbonus" value="<?=$_REQUEST['txtbonus']?>" />
								<?php echo $l_note;?>
								<input onkeypress="return enterTable(event,this.id,'0');" style="width:200px;height:24px" type="text" id="txtnote" name="txtnote" value="<?=$_REQUEST['txtnote']?>" />
								<input type="button" name="btbonusok" onclick="bonus(1);" id="btbonusok" value="<?php echo $l_ok?>"  class="buttonProject" />
								<input type="button" name="btbonuscancel" onclick="bonus(0);" id="btbonuscancel" value="<?php echo $l_cancel?>"  class="buttonProject" />
							</td>
						</tr>
						<tr>
							<td colspan="3">
								<input type="button" name="btsave" onclick="save(<?=$_REQUEST['nam']?>,<?=$_REQUEST['thang']?>);" id="btsave" value="<?php echo $l_save?>"  class="btnupbg btnupload" />
							</td>
						</tr>
					</table>
					
					<?php 
				}
			?>
				
			</div>
			<?php //mysql_close($connection);?>